package DataStr.homework04.h2;

public class SequentialSearch {
    public static int SequentialSearch(int[]arr,int target){
        int count=0;
        for(int i=0;i<arr.length;i++){
            count++;
            if(arr[i]==target){
                return count;
            }
        }
        return count;
    }
    public static void main(String[]args){
        int[]arr={5,11,23,35,51,64,72,85,88,90,98};
        int target1=30;
        int target2=72;
        int count1=SequentialSearch(arr,target1);
        System.out.println("顺序查找:");
        System.out.println(target1+"的比较次数:"+count1);
        System.out.println(target1+"的查找结果:"+((count1<arr.length)?"找到":"未找到"));
        int count2=SequentialSearch(arr,target2);
        System.out.println(target2+"的比较次数:"+count2);
        System.out.println(target2+"的查找结果:"+((count2<arr.length)?"找到":"未找到"));
    }
}
